const Koa = require('koa')
const fs = require('fs')
const static = require('koa-static')
const path = require('path')
const onerror = require('koa-onerror')
const app = new Koa()

app.use(
  static(path.join(__dirname, './dist'))
)
app.use(async (ctx) => {
  let url = ctx.url
  if (url == '/') {
    ctx.body = await render()
  }
})

function render () {
  return new Promise((resolve, reject) => {
    fs.readFile('index1.html', 'utf-8', (err, data) => {
      if (!err) {
        resolve(data)
      }
    })
  })
}
onerror(app)
app.on("error",function(){});
app.listen(3000, () => {
  console.log('server is running')
})

